package cn.jdx.tools.md2html.entity;

import java.util.ArrayList;
import java.util.List;

/*
【功能】:拼接html主干结构
 */
public class HtmlStructure {
    private String title = "主页";
    private String qq = "";//展示icon
    private String content = "";//内容

    private List<String> javaScript;
    private List<String> css;

    public HtmlStructure() {
        this.javaScript = new ArrayList<>();
        this.css = new ArrayList<>();
    }

    public void addTagJavaScript(String jsContent){
        String tag = "<script>\n" +jsContent+ "\n</script>";
        javaScript.add(tag);
    }

    public void addTagJavaScriptLink(String src){
        String tag = "<script type=\"text/javascript\" src=\""+src+"\"></script>";
        javaScript.add(tag);
    }

    public void addTagCss(String cssContent){
        String tag = "<style>\n" +cssContent+ "\n</style>";
        css.add(tag);
    }

    public void addTagCssLink(String href){
        String tag = "<link rel=\"stylesheet\" href=\""+href+"\"/>";
        css.add(tag);
    }


    public String getHtmlContent() {

        String title= "\t<title>"+getTitle()+"</title>\n";

        String str1 = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "\t<meta charset=\"utf-8\">\n" + title ;

        String icon = "\t<link rel=\"icon\" href=\"http://q.qlogo.cn/headimg_dl?dst_uin="+getQq()+"&spec=640&img_type=jpg\">\n";


        String str2 = "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n" +
                "\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\">\n" + icon;

        //加载css标签
        StringBuilder style = new StringBuilder("");
        if (css!=null&&css.size()>0){
            for (int i = 0; i < css.size(); i++) {
                style.append(css.get(i)+"\n");
            }
        }

        //加载javaScript标签
        StringBuilder js = new StringBuilder("");
        if (javaScript!=null&&javaScript.size()>0){
            for (int i = 0; i < javaScript.size(); i++) {
                js.append(javaScript.get(i)+"\n");
            }
        }


        String content1 = "\t<div>"+getContent()+"</div>\n";




        String str3 = style.toString() +
                "</head>\n" +
                "<body>\n" +
                content1 +
                js.toString()+//这里是<script>内容
                "</body>\n" +
                "</html>";

        return str1+str2+str3;
    }

    private String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    private String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }



    private String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

}
